terraform {
  required_version = ">= 0.14"

  required_providers {
    alicloud = {
      source = "hashicorp/alicloud"
      version = "1.153.0"
    }
  }
}

provider "alicloud" {
  profile = "default"
}

data "alicloud_zones" "all" {
}

module "vpc" {
  source = "../../2-vpc"

  vpc_name        = "ebike"
  vpc_cidr        = "192.168.0.0/16"
  vpc_description = "测试vpc"
  vpc_tags = {
    created = "Terraform"
  }

  vswitch_name       = "ebike"
  availability_zones = data.alicloud_zones.all.ids
  vswitch_cidrs      = [for i, v in data.alicloud_zones.all.ids : format("192.168.%d.0/24", i + 1)]
  vswitch_tags = {
    created = "Terraform"
  }

}

module "rds-redis" {
  source = "../"

  exist_azs         = module.vpc.availability_zones
  exist_vswitch_ids = module.vpc.vswitch_ids

  instance_name         = "mysql"
  // rds.mysql.s2.large mysql.n2.small.2c rds.mysql.t1.small
  instance_type         = "rds.mysql.t1.small"
  // local_ssd cloud_essd cloud_essd2 cloud_essd3
  instance_storage_type = "local_ssd"
  instance_storage      = 50
  multi_zone = true

  databases = [
    {
      name          = "pipeline"
      character_set = "utf8"
      description   = "pipeline"
    }
  ]

  accounts = [
    {
      name          = "user1"
      password      = "1234abc"
      type          = "Normal"
      privilege     = "ReadWrite"
      databases     = ["pipeline"]
    }
  ]

}

